package com.lbg.drug.service.impl;

import com.lbg.drug.commont.untils.PageUtils;
import com.lbg.drug.dto.FactPage;
import com.lbg.drug.entity.DrugCategory;
import com.lbg.drug.entity.DrugFacts;
import com.lbg.drug.mapper.DrugCategoryMapper;
import com.lbg.drug.mapper.DrugFactsMapper;
import com.lbg.drug.service.DrugFactsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lbg
 * @since 2022-04-26
 */
@Service
public class DrugFactsServiceImpl implements DrugFactsService {



    @Autowired
    private DrugFactsMapper drugFactsMapper;

    @Autowired
    private DrugCategoryMapper drugCategoryMapper;

    @Override
    public PageUtils getDact(FactPage factPage) {
        factPage.setCurrIndex((factPage.getPageNo()-1)*factPage.getPageSize());
        factPage.setEndIndex(factPage.getPageSize());
        PageUtils pageUtils = new PageUtils(drugFactsMapper.getAllByDrugName(factPage),drugFactsMapper.getCount(factPage));

        return pageUtils;
    }

    @Override
    public void update(DrugFacts drugFacts) {

        drugFactsMapper.updateById(drugFacts);

    }

    @Override
    public void delete(String id) {
        drugFactsMapper.deleteById(id);

    }

    @Override
    public String intsert(DrugFacts drugFacts) {
        DrugCategory drugCategory = new DrugCategory();
        drugCategory.setDrugType(drugFacts.getDrugType());
        drugCategory.setDrugCmmonName(drugFacts.getDrugCmmonName());

        drugCategoryMapper.insert(drugCategory);


        drugFactsMapper.insert(drugFacts);

        return drugFacts.getDrugId() ;

    }
}
